#pragma once
#include <iostream>
#include <memory>
#include "Protocol.hpp"


class Calculate
{
    enum
    {
        Success,
        DivZeroErr
    };
public:
    Calculate(){}
    ~Calculate(){}
    std::shared_ptr<Response> Cal(std::shared_ptr<Request> req)
    {
        std::shared_ptr<Response> resp = factory.BuildResponse();
        resp->SetCode(Success);
        switch(req->getOper())
        {
            case '+': resp->SetResult(req->GetX() + req->GetY()); break;
            case '-': resp->SetResult(req->GetX() - req->GetY()); break;
            case '*': resp->SetResult(req->GetX() * req->GetY()); break;
            case '/': {req->GetY() == 0 ? resp->SetCode(DivZeroErr) : 
                resp->SetResult(req->GetX() / req->GetY());}; break; 
            default: break;
        }
        return resp;
    }
private:
    Factory factory;
};